package com.wonders.frame.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author qiu
 * @date 2019-11-07 15:28
 */
public class DateUtil {
    public static final String DATE_TIME="yyyy-MM-dd HH:mm:ss";
    public static final String DATE="yyyy-MM-dd";
    public static final String YEAR_MONTH="yyyy-MM";

    /**
     * 字符串转date
     * @param strDate
     * @param type
     * @return
     * @throws ParseException
     */
    public static Date stringToDate(String strDate, String type) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat(type);
        Date date = formatter.parse(strDate);
        return  date;
    }

    /**
     * date转字符串
     * @param date
     * @param type
     * @return
     */
    public static String dateToString(Date date,String type){
        SimpleDateFormat formatter = new SimpleDateFormat(type);
        String strDate=formatter.format(date);
        return strDate;
    }


    /**
     * 比较两个时间相差的秒数
     * @param date
     * @param date1
     * @return
     */
    public static Long getDifference(Date date,Date date1){
        Long diff=(date1.getTime()-date.getTime())/1000;
        return diff;
    }


}
